import pygame, math, sys, random
from Player import Terminator

class Shotgun(pygame.sprite.Sprite):
    def __init__(self, position, direction, screenSize):
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.images = []
        self.images += [pygame.image.load("rsc/Bullet/Bulletdown.png")]
        self.frame = 0
        self.maxFrame = len(self.images)-1
        self.image = self.images[self.frame]
        self.rect = self.image.get_rect() 
        self.baseRect = self.rect
        self.rect = self.image.get_rect()
        self.speed = 20
        self.damage = 32
        self.x = position[0]
        self.y = position[1]
        self.realx = position[0]
        self.realy = position[1]
        #self.angle = player.angle
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.radius = (self.rect.width/2 + self.rect.height/2)/2
        self.living = False
        self.place(position)
        self.dir = direction
        print "class", direction
        
    def  __str__(self):
        return ("I'm the SHOTGUN and >>>>>I<<<<< am KILLING " + str(self.rect.center) + str(self.speed) + str(self.living))
 
    def place(self, position):
        self.rect.center = position
        
    def die(self):
        self.living = False
        
    def move(self):
        if self.dir == "left":
            self.realx += -self.speed
            self.place([self.realx, self.realy])
            [pygame.image.load("rsc/Bullet/Bulletleft.png")]
        elif self.dir == "right":
            self.realx += self.speed
            self.place([self.realx, self.realy])
            [pygame.image.load("rsc/Bullet/Bulletright.png")]
        elif self.dir == "up":
            self.realy += -self.speed
            self.place([self.realx, self.realy])
            [pygame.image.load("rsc/Bullet/Bulletup.png")]
        elif self.dir == "down":
            self.realy += self.speed
            self.place([self.realx, self.realy])
            [pygame.image.load("rsc/Bullet/Bulletdown.png")]
        
        #self.realx += self.speed
        #self.place([self.realx, self.realy])
        #print "I've moved", self.speed
        
        '''
    def newPos(self):
        self.angle = self.angle % 360
        if self.angle < 0:
            self.angle = 360 - math.abs(self.angle)
        if self.angle == 0:
            self.x += self.speed
            self.y += 0
        elif 0 < self.angle < 90: 
            self.x += self.speed * math.cos(math.radians(self.angle))
            self.y += -self.speed * math.sin(math.radians(self.angle))
        elif self.angle == 90:
            self.x += 0
            self.y += -self.speed
        elif 90 < self.angle < 180:
            self.x += -self.speed * math.sin(math.radians(self.angle-90))
            self.y += -self.speed * math.cos(math.radians(self.angle-90))
        elif self.angle == 180:
            self.x += -self.speed
            self.y += 0
        elif 180 < self.angle < 270:
            self.x += -self.speed * math.cos(math.radians(self.angle-180))
            self.y += self.speed * math.sin(math.radians(self.angle-180))
        elif self.angle == 270:
            self.x += 0
            self.y += self.speed 
        elif 270 < self.angle < 360:
            self.x += self.speed * math.sin(math.radians(self.angle-270))
            self.y += self.speed * math.cos(math.radians(self.angle-270))
 
    def move (self):
        #self.newPos()
        self.rect.center = [int(self.x), int(self.y)]
        '''
   
    
    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 or self.rect.right > screenWidth):
                self.living = False 
        if (self.rect.top < 0 or self.rect.top > screenHeight):
                self.living = False
            
            
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))            

    
    def enemyCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):                 
                    self.kill()
                    other.kill()
                     
    def collidePlayer(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):                 
                    other.die()
                    self.die()     
                        
    def update(*args):
        self = args[0]
        self.xOffset = args[1]
        self.yOffset  = args[2]
        self.scrollingx = args[3]
        self.scrollingy = args[4]
        self.didHit = False
        self.move()
        
                        
                        
    
    
        